﻿package com.mxprojects.io
{
	import com.mxprojects.gui.DefaultDialog;
	import com.mxprojects.language.Language;
	
	public class Config 
	{
		//this is the motherload of static vars, the whole forum uses this stuff
		public static var BOARD_NAME:String;
		public static var GUEST_GROUP_ID:int;
		public static var ADMIN_EMAIL:String;
		public static var INSTALL_DIRECTORY:String;
		public static var IMAGE_DIRECTORY:String;
		public static var DEFAULT_USER_TITLE:String;
		public static var ABSOLUTE_INSTALL_PATH:String;
		public static var ADMIN_MAIL_ON_THREAD_CHANGE:int;
		public static var THREADS_PER_PAGE:int;
		public static var POSTS_PER_PAGE:int;
		public static var MAX_AVATAR_FILE_SIZE:int;
		public static var MAX_AVATAR_WIDTH:int;
		public static var MAX_AVATAR_HEIGHT:int;
		public static var MAX_IMAGE_FILE_SIZE:int;
		public static var MAX_IMAGE_WIDTH:int;
		public static var MAX_IMAGE_HEIGHT:int;
		public static var LANGUAGE:String;
		public static var LANGUAGE_DIRECTORY:String;
		public static var PRIVATE_MESSAGE_LIMIT:int;
		public static var PRIVATE_MESSAGES_PER_PAGE:int;
		public static var MAX_DAYS_NEW_THREAD:int;
		public static var DEFAULT_INPUT_WIDTH:int;
		public static var POST_GAP:int;
		public static var TEXT_PADDING:int;
		public static var MESSAGE_DIVIDER:String;
		public static var ADD_AVATAR_ON_REGISTER:int;
		public static var LAST_ONLINE_TIMEOUT:int;
		public static var MOST_ONLINE_USERS:String;
		public static var CATEGORY_DATE_FORMAT:String;
		public static var ONLINE_USER_GAP_LENGTH:int;
		public static var CSS_LOCATION:String;
		public static var BREADCRUMB_SEPARATOR:String;
		public static var SEARCH_PAGES_TO_CACHE:int;
		public static var USERNAME_RESTRICTED_CHARS:String;
		public static var MAX_USERNAME_LENGTH:int;
		public static var AVATAR_UPLOAD_SUB_DIRECTORY:String;
		public static var POST_UPLOAD_SUB_DIRECTORY:String;
		public static var EXTRA_UPLOAD_SUB_DIRECTORY:String;
		public static var MAX_UPLOAD_FILES_POST:int;
		public static var COLUMN_PADDING:int;
		public static var SEARCH_CATEGORY_COLUMNS:int;
		public static var NETWORK_ICON_WIDTH:int;
		public static var NETWORK_ICON_HEIGHT:int;
		public static var LOGIN_DIALOG_WIDTH:int;
		public static var LOADING_ANIMATION_Y:int;
		public static var BOARD_EMAIL:String;
		public static var BUTTON_DISABLED_ALPHA:Number;
		public static var BUTTON_PADDING:int;
		public static var PRIVATE_MESSAGE_AUTO_CHECK_MINS:Number;
		public static var PRIVATE_MESSAGE_AUTO_CHECK_COUNT:int;
		public static var DEFAULT_POPUP_WIDTH:int;
		public static var DEFAULT_POPUP_HEIGHT:int;
		public static var CREATE_POST_POPUP_WIDTH:int;
		public static var CREATE_POST_POPUP_HEIGHT:int;
		public static var ANNOUCEMENT_DISPLAY_ORDER:int;
		public static var POST_SUBSCRIBE_BY_DEFAULT:int;
		public static var DEFAULT_LINE_HEIGHT:int = 1; //debating on putting this one in the CSS... Seems odd to.
		
		public static function init(baseURL:String):void {
			//this will load the database config into Flash so we can tap the resources
			if(baseURL == null){
				baseURL = MXP3.DEBUG_URL;
			}
			
			//set the base url in the Server Handler
			ServerHandler.BASE_URL = baseURL;
			
			//get the config action
			var serverHandler:ServerHandler = new ServerHandler();
			serverHandler.transmitData("config.php");
			serverHandler.listenForData(processData);
		}
		
		public static function processData(event:CustomEvent):void {
			//get the data
			var config:Object = event.getServerData();
			
			//make sure things went ok
			if(config.output == "configError"){
				//well this is pretty bad
				DefaultDialog.show("There was an error loading the config.php file.");
			}else if(config.output == "success"){				
				//set each of the vars... this is gonna be bananas
				BOARD_NAME = config.BOARD_NAME;
				GUEST_GROUP_ID = config.GUEST_GROUP_ID;
				ADMIN_EMAIL = config.ADMIN_EMAIL;
				INSTALL_DIRECTORY = config.INSTALL_DIRECTORY;
				IMAGE_DIRECTORY = config.IMAGE_DIRECTORY;
				DEFAULT_USER_TITLE = config.DEFAULT_USER_TITLE;
				ABSOLUTE_INSTALL_PATH = config.ABSOLUTE_INSTALL_PATH;
				ADMIN_MAIL_ON_THREAD_CHANGE = config.ADMIN_MAIL_ON_THREAD_CHANGE;
				THREADS_PER_PAGE = config.THREADS_PER_PAGE;
				POSTS_PER_PAGE = config.POSTS_PER_PAGE;
				MAX_AVATAR_FILE_SIZE = config.MAX_AVATAR_FILE_SIZE;
				MAX_AVATAR_WIDTH = config.MAX_AVATAR_WIDTH;
				MAX_AVATAR_HEIGHT = config.MAX_AVATAR_HEIGHT;
				MAX_IMAGE_FILE_SIZE = config.MAX_IMAGE_FILE_SIZE;
				MAX_IMAGE_WIDTH = config.MAX_IMAGE_WIDTH;
				MAX_IMAGE_HEIGHT = config.MAX_IMAGE_HEIGHT;
				LANGUAGE = config.LANGUAGE;
				LANGUAGE_DIRECTORY = config.LANGUAGE_DIRECTORY;
				PRIVATE_MESSAGE_LIMIT = config.PRIVATE_MESSAGE_LIMIT;
				PRIVATE_MESSAGES_PER_PAGE = config.PRIVATE_MESSAGES_PER_PAGE;
				MAX_DAYS_NEW_THREAD = config.MAX_DAYS_NEW_THREAD;
				DEFAULT_INPUT_WIDTH = config.DEFAULT_INPUT_WIDTH;
				POST_GAP = config.POST_GAP;
				TEXT_PADDING = config.TEXT_PADDING;
				MESSAGE_DIVIDER = config.MESSAGE_DIVIDER;
				ADD_AVATAR_ON_REGISTER = config.ADD_AVATAR_ON_REGISTER;
				LAST_ONLINE_TIMEOUT = config.LAST_ONLINE_TIMEOUT;
				MOST_ONLINE_USERS = config.MOST_ONLINE_USERS;
				CATEGORY_DATE_FORMAT = config.CATEGORY_DATE_FORMAT;
				ONLINE_USER_GAP_LENGTH = config.ONLINE_USER_GAP_LENGTH;
				CSS_LOCATION = config.CSS_LOCATION;
				BREADCRUMB_SEPARATOR = config.BREADCRUMB_SEPARATOR;
				SEARCH_PAGES_TO_CACHE = config.SEARCH_PAGES_TO_CACHE;
				USERNAME_RESTRICTED_CHARS = config.USERNAME_RESTRICTED_CHARS;
				MAX_USERNAME_LENGTH = config.MAX_USERNAME_LENGTH;
				AVATAR_UPLOAD_SUB_DIRECTORY = config.AVATAR_UPLOAD_SUB_DIRECTORY;
				POST_UPLOAD_SUB_DIRECTORY = config.POST_UPLOAD_SUB_DIRECTORY;
				EXTRA_UPLOAD_SUB_DIRECTORY = config.EXTRA_UPLOAD_SUB_DIRECTORY;
				MAX_UPLOAD_FILES_POST = config.MAX_UPLOAD_FILES_POST;
				COLUMN_PADDING = config.COLUMN_PADDING;
				SEARCH_CATEGORY_COLUMNS = config.SEARCH_CATEGORY_COLUMNS;
				NETWORK_ICON_WIDTH = config.NETWORK_ICON_WIDTH;
				NETWORK_ICON_HEIGHT = config.NETWORK_ICON_HEIGHT;
				LOGIN_DIALOG_WIDTH = config.LOGIN_DIALOG_WIDTH;
				LOADING_ANIMATION_Y = config.LOADING_ANIMATION_Y;
				BOARD_EMAIL = config.BOARD_EMAIL;
				BUTTON_DISABLED_ALPHA = config.BUTTON_DISABLED_ALPHA;
				BUTTON_PADDING = config.BUTTON_PADDING;
				PRIVATE_MESSAGE_AUTO_CHECK_MINS = config.PRIVATE_MESSAGE_AUTO_CHECK_MINS;
				PRIVATE_MESSAGE_AUTO_CHECK_COUNT = config.PRIVATE_MESSAGE_AUTO_CHECK_COUNT;
				DEFAULT_POPUP_WIDTH = config.DEFAULT_POPUP_WIDTH;
				DEFAULT_POPUP_HEIGHT = config.DEFAULT_POPUP_HEIGHT;
				CREATE_POST_POPUP_WIDTH = config.CREATE_POST_POPUP_WIDTH;
				CREATE_POST_POPUP_HEIGHT = config.CREATE_POST_POPUP_HEIGHT;
				ANNOUCEMENT_DISPLAY_ORDER = config.ANNOUCEMENT_DISPLAY_ORDER;
				POST_SUBSCRIBE_BY_DEFAULT = config.POST_SUBSCRIBE_BY_DEFAULT;
				
				//load the language file and start the loading of the forum
				Language.setupLanguage(LANGUAGE);
			}
		}
	}
}